Unlike the break statements, the continue statements continue the
loop and yet do not let the next line get executed in the current loop.
Run the preceding program by replacing break with continue and
observe the output.
2.5.14.7 Conditional (or ternary) Operators
We already discussed a ternary operator where we first evaluate the
condition on the left and, depending upon true or false, either of the
two values on the right is chosen and returned.
Refer to the following example:
Syntax: if condition true ? then Result1: else Result 2
The following is the sample code:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
contract ConditionalContract {
function condition(uint a, uint b) public pure returns(uint)
{
return a > b ? 11 : 22;
}
}
You can observe how simple and concise the code is in comparison
to the if-else statement. Ternary operators are used when the
number of conditions are limited to only two. However, if they are
more, then we have to use the if-then-else statement.
2.5.15 View Function
In a function marked with a view keyword, we are not supposed to
modify any of the state variables.
The following statements are considered to be modifying the state:
1. Writing to state variables
2. Emitting events
3. Creating other contracts